<?php
require_once(dirname(__FILE__) . "/settings.inc.php");
require_once(dirname(__FILE__) . "/functions.php");
require_once(dirname(__FILE__) . "/XmlSerializer.class.php");

error_reporting(E_ALL); 
ini_set("display_errors", 1);

/**
*
*
*/
function rowCount() {
	global $conn, $filter_field, $filter_type;
	
	$id = intval($_GET['id']);
	$date = $_GET['date'];

	$where = "";
	if (@$_REQUEST['filter'] != "") {
		$where = "WHERE " . $filter_field . " LIKE " . GetSQLValueStringForSelect(@$_REQUEST["filter"], $filter_type);	
	}

	//calculate the number of rows in this table
	$rscount = mysql_query("SELECT COUNT(person_id) AS cnt FROM presence WHERE DATE = '$date' AND course_id = $id"); 
	$row_rscount = mysql_fetch_assoc($rscount);
	$totalrows = (int) $row_rscount["cnt"];
	
	//create the standard response structure
	$toret = array(
		"data" => $totalrows, 
		"metadata" => array()
	);

	return $toret;
}


if ($conn === false) {
	$ret = array(
		"data" => array("error" => "database connection error, please check your settings !"), 
		"metadata" => array()
	);
} else {
	mysql_select_db($database_conn, $conn);
	/**
	 * simple dispatcher. The $_REQUEST["method"] parameter selects the operation to execute. 
	 * must be one of the values findAll, insert, update, delete, Count
	 */
	// execute the necessary function, according to the operation code in the post variables
	switch (@$_REQUEST["method"]) {
		case "RowCount":
			$ret = rowCount();
		break;
	}
}

$serializer = new XmlSerializer();
echo $serializer->serialize($ret);
die();
?>